package com.wwj.task;


import com.wwj.common.constant.MessageConstant;
import com.wwj.mapper.OrderMapper;
import com.wwj.pojo.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

//定时任务类
@Component
@Slf4j
public class OrderTask {

    @Resource
    private OrderMapper orderMapper;

    //处理超时订单
    @Scheduled(cron = "0 0 1 * * ? ")

    public  void processDeliveryOrder(){
        log.info("定时处理一直未审核的体检订单:{}", LocalDateTime.now());
        LocalDateTime localDateTime = LocalDateTime.now().plusMinutes(-60);
        List<Order> ordersList = orderMapper.getByStatusAndOrderTimeLT(Order.STATUS1, localDateTime);
        if(ordersList !=null && ordersList.size()>0){
            for (Order order : ordersList) {
                order.setStatus(Order.STATUS3);
                order.setReason(MessageConstant.REASON_BY_TASK);
                orderMapper.update(order);
            }
        }
    }

}
